package com.panopset.svg;

import java.awt.Image;
import java.util.Date;

import com.panopset.Util;
import com.panopset.UtilIO;
import com.panopset.sf.StatusIndicator;

/**
 * <a href="http://svg-cards.sourceforge.net/">svg-cards.svg</a>.
 *
 * @author Karl Dinwiddie
 *
 */
public class CardsSVG {

    private final int b;

//    private CardPainter cp;

//    private CardPainter getCp() {
//        if (cp == null) {
//            cp = new CardPainter(getDeckImage().getWidth(null), getDeckImage()
//                    .getHeight(null), new Suit[] {Suit.CLUB, Suit.DIAMOND,
//                    Suit.HEART, Suit.SPADE });
//        }
//        return cp;
//    }

    public CardsSVG(final int base) {
        b = base * 5 * 13;
    }

    private Image deckImage;

    public synchronized Image getDeckImage() {
        if (deckImage == null) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    new StatusIndicator(new StatusIndicator.Caboose() {
                             @Override
                             public boolean isActive() {
                                 return deckImage == null;
                             }

                             @Override
                             public String getMessage() {
                                 return Util
                                         .x("Loading card images");
                             }
                    }).show();
                }
            }
            ).start();
            deckImage = Svg2img.convert(UtilIO.getResourceStream(

            "/com/panopset/game/card/svg-cards.svg"), b);
        }
        return deckImage;
    }

}
